package com.ruoyi.web.controller.voit;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.voit.domain.ErrorLog;
import com.ruoyi.voit.service.IErrorLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 充电桩异常事件记录Controller
 * 
 * @author ruoyi
 * @date 2025-07-17
 */
@RestController
@RequestMapping("/voit/log")
public class ErrorLogController extends BaseController
{
    @Autowired
    private IErrorLogService errorLogService;

    /**
     * 查询充电桩异常事件记录列表
     */
    @PreAuthorize("@ss.hasPermi('voit:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErrorLog errorLog)
    {
        startPage();
        List<ErrorLog> list = errorLogService.selectErrorLogList(errorLog);
        return getDataTable(list);
    }

    /**
     * 导出充电桩异常事件记录列表
     */
    @PreAuthorize("@ss.hasPermi('voit:log:export')")
    @Log(title = "充电桩异常事件记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErrorLog errorLog)
    {
        List<ErrorLog> list = errorLogService.selectErrorLogList(errorLog);
        ExcelUtil<ErrorLog> util = new ExcelUtil<ErrorLog>(ErrorLog.class);
        util.exportExcel(response, list, "充电桩异常事件记录数据");
    }

    /**
     * 获取充电桩异常事件记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('voit:log:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") String logId)
    {
        return success(errorLogService.selectErrorLogByLogId(logId));
    }

    /**
     * 新增充电桩异常事件记录
     */
    @PreAuthorize("@ss.hasPermi('voit:log:add')")
    @Log(title = "充电桩异常事件记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErrorLog errorLog)
    {
        return toAjax(errorLogService.insertErrorLog(errorLog));
    }

    /**
     * 修改充电桩异常事件记录
     */
    @PreAuthorize("@ss.hasPermi('voit:log:edit')")
    @Log(title = "充电桩异常事件记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErrorLog errorLog)
    {
        return toAjax(errorLogService.updateErrorLog(errorLog));
    }

    /**
     * 删除充电桩异常事件记录
     */
    @PreAuthorize("@ss.hasPermi('voit:log:remove')")
    @Log(title = "充电桩异常事件记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable String[] logIds)
    {
        return toAjax(errorLogService.deleteErrorLogByLogIds(logIds));
    }
}
